import os
import sys
localDir = os.path.dirname(__file__)
curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))
grandparent = os.path.normpath(os.path.join(curpath, '../'))
sys.path.insert(0, grandparent)

import unittest

from lib.sql import Sql

from databases.sqlite import Sqlite
config = {"development" : {"db" : "sqlite:///:memory:"}}

class TestSql(unittest.TestCase):

    def testTruth(self):
        self.assertTrue(True)

    def testFormat(self):
        query = "SELECT * FROM users"
        sql = Sql([], query)

        self.assertEqual(query, sql.query)

    def testFormatMultiLine(self):
        alc = Sqlite(config['development']['db'])
        query = """SELECT
        *
        FROM
        users"""
        sql = Sql(alc, query)

        self.assertEqual("SELECT\n        *\n        FROM\n        users", sql.query)

    def testExecute(self):
        alc = Sqlite(config['development']['db'])
        alc._create_schema()
        query = """SELECT
        *
        FROM
        schema_info"""
        sql = Sql(alc, query)

        self.assertTrue(sql.execute())

if __name__ == "__main__":
    unittest.main()
